<?php
if ( count( get_included_files() ) == 1 ) die( '---' );

class PFLdocumentCompetence
{
	// Constructeur
	function PFLdocumentCompetence() 
        {
    	  $this->documentId = -1;
    	  $this->competenceId = -1;
	  $this->userId = -1;
	  $this->commentaire = "";

	  global $tableDocumentCompetence;    	
	  $this->table = $tableDocumentCompetence;
        }

	// Load
	function load()
	{
	  $sql = "SELECT * 
		  FROM `".$this->table."` 
		  WHERE 1=1";

	  if ($this->documentId != -1)
	  $sql .= " AND documentId = ".$this->documentId;

	  if ($this->competenceId != -1)
	  $sql .= " AND competenceId = ".$this->competenceId;

	  if ($this->userId != -1)
	  $sql .= " AND userId = ".$this->userId;

	  $data = claro_sql_query_fetch_all_rows($sql);

	  return $data;
	}

	// Save 
	function save()  
	{
		$this->delete();

		$sql = "INSERT INTO `".$this->table."`
			SET documentId = ".$this->documentId.",
			    userId = ".$this->userId.",
			    competenceId = ".$this->competenceId.",
			    commentaire = '".addslashes($this->commentaire)."'";
		 if( claro_sql_query($sql) )
		 {
		   return true;
		 }
		 else
		 {
		   return false;
		 }
	}

	// Delete
	function delete()
	{
		$sql = "DELETE FROM `".$this->table."` 
			WHERE documentId = ".$this->documentId."
			AND userId = ".$this->userId."
			AND competenceId = ".$this->competenceId;

		 if( claro_sql_query($sql) )
		 {
		   return true;
		 }
		 else
		 {
		   return false;
		 }
	}

	// documentId
	function getDocumentId()
	{
		return (int) $this->documentId;
	}
	
	function setDocumentId($value)
	{
		$this->documentId = $value;
	}

	// UserId
	function getUserId()
	{
		return (int) $this->userId;
	}

	function setUserId($value)
	{
		$this->userId = $value;
	}

	// competenceId
	function getCompetenceId()
	{
		return (int) $this->competenceId;
	}

	function setCompetenceId($value)
	{
		$this->competenceId = $value;
	}

	// commentaire
	function getCommentaire()
	{
		return (int) $this->commentaire;
	}

	function setCommentaire($value)
	{
		$this->commentaire = $value;
	}

	// Suppression d'un document
	function supprimerDocument()
	{
		$sql = "DELETE FROM `".$this->table."` 
			WHERE documentId = ".$this->documentId;

		 if( claro_sql_query($sql) )
		 {
		   return true;
		 }
		 else
		 {
		   return false;
		 }
	}
}
?>
